package cn.edu.cug.cs.gtl.apis.ui.model3duis.projecttree;

import cn.edu.cug.cs.gtl.apis.render.Render;
import cn.edu.cug.cs.gtl.apis.render.viewers.Viewer;
import cn.edu.cug.cs.gtl.apis.ui.AbstractApplication;
import cn.edu.cug.cs.gtl.apis.ui.model3duis.Model3dUIApp;
import cn.edu.cug.cs.gtl.apis.ui.modeller.ModellerApp;
import cn.edu.cug.cs.gtl.apis.ui.tree.Tree;
import cn.edu.cug.cs.gtl.apis.ui.tree.TreeSelectionListener;
import cn.edu.cug.cs.gtl.protos.Layer;
import cn.edu.cug.cs.gtl.protos.Map;
import cn.edu.cug.cs.gtl.protos.Project;

public class ProjectTreeSelectionListener extends TreeSelectionListener {
    public ProjectTreeSelectionListener(Tree tree, AbstractApplication theApp) {
        super(tree, theApp);
    }

    @Override
    protected void objectChanged(Object obj) {
        Object refObject = this.theTree.getCurrentReferencedObject();
        if(refObject instanceof Project){
            //Do Nothing
        }
        else if(refObject instanceof Map){
            getModel3dUIApp().setCurrentMap((Map) refObject);
        }
        else if(refObject instanceof Layer){
            //Table Panel切换显示当前图层的数据表
            getModel3dUIApp().setCurrentLayer((Layer) refObject);
            getModel3dUIApp().getTablePanel().reset();
        }
        else{

        }
    }

    public Render getRender() {
        return ((ModellerApp)theApp).getModel3dUIApp().getRender();
    }

    public Viewer getViewer(){
        return ((ModellerApp)theApp).getModel3dUIApp().getViewer();
    }

    public Model3dUIApp getModel3dUIApp(){
        return ((ModellerApp)theApp).getModel3dUIApp();
    }

    public Project getProject() {
        return ((ModellerApp)theApp).getModel3dUIApp().getProject();
    }
}
